package company.tx1;

import java.util.*;

public class Tx2 {

    public static void main(String[] args) {
        HashMap<Integer, HashSet<Integer>> dict = new HashMap<>();
        Scanner sc = new Scanner(System.in);
        // n个人
        int n = sc.nextInt();
        // m个团队
        int m = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < m; i++) {
            //团队人数
            int peoples = sc.nextInt();
            List<Integer> list = new ArrayList<>();
            for (int j = 0; j < peoples; j++) {
                //员工编号
                int no = sc.nextInt();
                list.add(no);
            }
            for (Integer no : list) {
                HashSet<Integer> tmp = dict.getOrDefault(no, new HashSet<>());
                tmp.addAll(list);
                dict.put(no, tmp);
            }
        }
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(0);
        while (!queue.isEmpty()) {
            Integer poll = queue.poll();
            HashSet<Integer> integers = dict.get(poll);
            for (Integer i : integers) {
                if (poll != i && !set.contains(i)) {
                    queue.add(i);
                    set.add(i);
                }
            }
        }
        System.out.println(set.size());
    }

}
